//
//  LoginViewController.m
//  TaurusXi
//
//  Created by xicheng on 15/12/2.
//  Copyright © 2015年 xicheng. All rights reserved.
//

#import "LoginViewController.h"
#import "CardBindViewController.h"
#import "HomeViewController.h"
#import "MD5_Utils.h"
#import "UserHelper.h"


@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UIButton *loginBt;
@property (weak, nonatomic) IBOutlet UITextField *phoneField;
@property (weak, nonatomic) IBOutlet UITextField *passwordBt;


@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitleText:@"登录"];
    [self.loginBt addTarget:self action:@selector(goToCardBindButton:) forControlEvents:UIControlEventTouchUpInside];
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)goToCardBindButton:(UIButton *)goToCardBindButton{

  [self showSimplePro];
   @weakify(self);
  [[Api shareApiInstance]loginWith:self.phoneField.text AndPassword: self.passwordBt.text AndResponce:^(id object) {
    @strongify(self);
    [self hideSimpleProWithDelay:0];
    
      [[UserHelper shareUserInstance]setUserId:[object objectForKey:@"userId"]];
      [[NSNotificationCenter defaultCenter]postNotificationName:@"login" object:@YES];
      [self leftBarButtonAction:nil];
   
  } AndError:^(id object, NSError *error) {
    @strongify(self);
    [self hideSimpleProWithDelay:0];
    if (object) {
      [self showPop:[NSString stringWithFormat:@"%@",[object objectForKey:@"msg"]]];
    }
  }];
}

-(void)viewWillDisappear:(BOOL)animated{
//  [super viewWillDisappear:animated];
  self.tabBarController.tabBar.hidden = NO;
  self.navigationController.navigationController.navigationBar.alpha = 0;

}


@end
